/**
 * @file 求 LCS 并给出这个最长字串
 * @author Ruiming Guo (guoruiming@stu.scu.edu.cn)
 * @brief
 * @version 1.0
 * @date 2022-05-10
 *
 * @copyright Copyright (c) 2022
 *
 **/

#include <bits/stdc++.h>
using namespace std;
const int N = 1010;
char a[N], b[N];
// dp[i][j] 表示 a 的前 i 项和 b 的前 j 项的 LCS
int dp[N][N];
int main() {
  cin >> a + 1 >> b + 1;
  int alen = strlen(a + 1), blen = strlen(b + 1);
  for (int i = 1; i <= alen; ++i)
    for (int j = 1; j <= blen; ++j) {
      dp[i][j] = max({dp[i][j], dp[i - 1][j], dp[i][j - 1]});
      if (a[i] == b[j]) dp[i][j] = max(dp[i][j], dp[i - 1][j - 1] + 1);
    }

  int count = dp[alen][blen];
  string result;
  // 事实：最优子串的每一个字符s[idx]（也就是a[i], b[j]）都有 dp[i][j] == idx
  for (int i = alen; i > 0; --i)
    for (int j = blen; j > 0; --j) {
      if (a[i] == b[j] && dp[i][j] == count) {
        result += a[i];
        count--;
        break;
      }
      if (count == 0) break;
    }

  reverse(result.begin(), result.end());
  cout << result << endl;
}
